/**
 * 排序以后，直接累加并判断即可
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;

int N;
llt M;
vector<llt> A;
vector<llt> S;

int proc(){
	sort(A.begin(), A.end());
    
	S.assign(N, 0);
	S[0] = A[0];
	int ans = S[0] <= M ? 1 : 0;
	for(int i=1;i<N;++i){
		if(M >= (S[i] = S[i - 1] + A[i])){
			ans = i + 1;
		}
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> N >> M;
	A.assign(N, {});
	for(auto & i : A) cin >> i;
	cout << proc() << "\n";
    return 0;
}